/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NODE_BINDING_LUA_ENGINE_H_
#define NODE_BINDING_LUA_ENGINE_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstdint>
#include "node/macros.h"
extern "C"
{
#include "node-binding/lua/lua.h"
}

namespace node_binding {
    
    enum NodeModule
    {
        NMOD_SYS = 0x001,   // sys module
        NMOD_UTIL = 0x002,  // util module
        NMOD_HTTP = 0x004,  // http module

        NMOD_ALL = NMOD_SYS | NMOD_UTIL | NMOD_HTTP
    };

    class LuaEngine
    {
    public:
        LuaEngine(int init_modules = NMOD_ALL);
        ~LuaEngine(void);

        void LoadModules(int modules);
        void DoFile(const char *filename);

    private:
        typedef int(*TOLUA_MODULE_OPEN)(lua_State *);
        void LoadModule(const char *name, TOLUA_MODULE_OPEN fn);

        lua_State *lua_state_;
        ::std::uint32_t mod_load_mask_;
        DISALLOW_COPY_AND_ASSIGN(LuaEngine);
    };

}

#endif // NODE_BINDING_LUA_ENGINE_H_
